package oocl.ita.eordering.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import oocl.ita.eordering.dao.OrderDao;
import oocl.ita.eordering.po.Order;

@Repository
public class OrderDaoImpl implements OrderDao {
	@PersistenceContext(name = "un")
	private EntityManager em;

	@Override
	public List<Order> showOrderByClientId(int cId) {
		String jpql = "select o from Order o where o.cId=:cId";
		@SuppressWarnings("unchecked")
		List<Order> ls = em.createQuery(jpql).setParameter("cId", cId).getResultList();
		if (ls.isEmpty())
			return null;
		else
			return ls;
	}

	@Override
	public int addOrder(Order order) {
		em.persist(order);
		return order.getcId();
	}

}
